package com.token.iot.bratterycharging.gateway.business;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.outstanding.framework.core.PendingException;
import com.token.iot.bratterycharging.gateway.IDGeneration;
import com.token.iot.bratterycharging.gateway.api.DeviceParam;
import com.token.iot.bratterycharging.gateway.utils.ByteUtil;
/**
 * 获取设备参数
 * @author chenzhixuan
 *
 */
@Component("DCNDuplexProcessor")
public class DCNDuplexProcessor extends DuplexProcessor {

	@Override
	public String request(String imei, Map<String, String> params) throws PendingException {
		String c = "DCN";
		String sessionId = IDGeneration.createSeesionID();
		String command = null;
		command = c + sessionId + "/";
		loger.info("the send =" + new String(command));
		byte[] cc = ByteUtil.addFlag(command.getBytes());
		context.writeAndFlush(cc);
		return sessionId;
		
	}

	@Override
	public DeviceParam response(String response) throws PendingException {
		String leftStr = response.substring(14);
		loger.info(" the DCN leftStr="+leftStr);
		String[] params = leftStr.split("#/#");
		DeviceParam dp = new DeviceParam();
		dp.setMaxPower(params[0]);
		dp.setMoney(params[1]);
		dp.setFirst(params[2]);
		dp.setSecond(params[3]);
		dp.setThird(params[4]);
		return dp;

	}

}
